package com.xinyu.event;

import java.util.Collections;
import java.util.List;

public class StatusChangeEvent {

    public enum EntityType {
        TASK("任务"),
        DAILY("问题");

        private final String displayName;

        EntityType(String displayName) {
            this.displayName = displayName;
        }

        public String getDisplayName() {
            return displayName;
        }
    }

    private final EntityType entityType;
    private final Integer entityId;
    private final String entityTitle;
    private final Integer oldState;
    private final Integer newState;
    private final String newStateLabel;
    private final String reason;
    private final Integer operatorId;
    private final List<Integer> recipientUserIds;
    private final String detailUrl;
    private final boolean stateChanged;
    private final boolean assigneeChanged;
    private final Integer previousResponsibleUserId;
    private final Integer newResponsibleUserId;

    public StatusChangeEvent(EntityType entityType,
                              Integer entityId,
                              String entityTitle,
                              Integer oldState,
                              Integer newState,
                              String newStateLabel,
                              String reason,
                              Integer operatorId,
                              List<Integer> recipientUserIds,
                              String detailUrl,
                              boolean stateChanged,
                              boolean assigneeChanged,
                              Integer previousResponsibleUserId,
                              Integer newResponsibleUserId) {
        this.entityType = entityType;
        this.entityId = entityId;
        this.entityTitle = entityTitle;
        this.oldState = oldState;
        this.newState = newState;
        this.newStateLabel = newStateLabel;
        this.reason = reason;
        this.operatorId = operatorId;
        this.recipientUserIds = recipientUserIds == null ? Collections.emptyList() : recipientUserIds;
        this.detailUrl = detailUrl;
        this.stateChanged = stateChanged;
        this.assigneeChanged = assigneeChanged;
        this.previousResponsibleUserId = previousResponsibleUserId;
        this.newResponsibleUserId = newResponsibleUserId;
    }

    public EntityType getEntityType() {
        return entityType;
    }

    public Integer getEntityId() {
        return entityId;
    }

    public String getEntityTitle() {
        return entityTitle;
    }

    public Integer getOldState() {
        return oldState;
    }

    public Integer getNewState() {
        return newState;
    }

    public String getNewStateLabel() {
        return newStateLabel;
    }

    public String getReason() {
        return reason;
    }

    public Integer getOperatorId() {
        return operatorId;
    }

    public List<Integer> getRecipientUserIds() {
        return recipientUserIds;
    }

    public String getDetailUrl() {
        return detailUrl;
    }

    public boolean isMeaningfulChange() {
        return stateChanged || assigneeChanged;
    }

    public boolean isStateChanged() {
        return stateChanged;
    }

    public boolean isAssigneeChanged() {
        return assigneeChanged;
    }

    public Integer getPreviousResponsibleUserId() {
        return previousResponsibleUserId;
    }

    public Integer getNewResponsibleUserId() {
        return newResponsibleUserId;
    }
}
